﻿Shader "Custom/Instanced/Texture_Instanced"
{
    Properties
    {
        _MainTex ("Base (RGB) Trans (A)", 2D) = "white" { }
        _Color ("Color", Color) = (1, 1, 1, 1)
    }
    
    SubShader
    {
        Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" }
        
        Pass
        {
            ZWrite On
            Blend SrcAlpha OneMinusSrcAlpha
            
            CGPROGRAM
            
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_instancing
            
            #include "UnityCG.cginc"
            
            struct a2v
            {
                float4 vertex: POSITION;
                float2 uv: TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
            
            struct v2f
            {
                float2 uv: TEXCOORD0;
                float2 uv2: TEXCOORD1;
                float4 vertex: SV_POSITION;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
            
            sampler2D _MainTex;
            float4 _MainTex_ST;
            float4 _Color;
            v2f vert(a2v v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_TRANSFER_INSTANCE_ID(v, o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }
            
            fixed4 frag(v2f i): SV_Target
            {
                UNITY_SETUP_INSTANCE_ID(i);
                fixed4 mainTexCol = tex2D(_MainTex, i.uv);
                fixed4 albedo = mainTexCol * _Color;
                
                // fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT * albedo.rgb;
                // float3 worldNormal = UnityObjectToWorldNormal(i.normal);
                // float3 lightDir = UnityWorldSpaceLightDir(i.vertex);
                // fixed3 diffuse = _LightColor0.rgb * albedo.rgb * saturate(dot(worldNormal, lightDir));
                fixed4 color = fixed4(albedo.rgb, mainTexCol.a * _Color.a);
                clip(color.a - 0.01);
                return color;
            }
            ENDCG
            
        }
    }
    
    Fallback "Legacy Shaders/Transparent/VertexLit"
}
